Title: [271396] trunk/Source
Revision
271396
Author
[email protected]
Date
2021-01-12 02:55:16 -0800 (Tue, 12 Jan 2021)

Log Message

[GStreamer] Lazy initialization support
https://bugs.webkit.org/show_bug.cgi?id=209332

Reviewed by Carlos Garcia Campos.

Source/WebCore:

The GStreamer library is now mostly used from the WebProcess only. The last remaining
GStreamer usage from the UIProcess is triggered by the webkit_web_view_can_show_mime_type()
API, which is acceptable for now.

GStreamer will now be initialized only if it is needed, so lazy initialization calls were
added in the various WebCore components relying on the library.

Based on preliminary patches by Charlie Turner <[email protected]> and Victor M Jaquez <[email protected]>.

* platform/audio/gstreamer/AudioDestinationGStreamer.cpp:
(WebCore::initializeDebugCategory): Lazily initialize GStreamer and load our in-house
elements (webkitwebaudiosrc is needed by this module).
* platform/audio/gstreamer/AudioFileReaderGStreamer.cpp:
(WebCore::initializeDebugCategory): Lazily initialize GStreamer.
* platform/graphics/gstreamer/GStreamerCommon.cpp:
(WebCore::addGStreamerOptionsFromUIProcess): Store command-line arguments from the UIProcess.
(WebCore::ensureGStreamerInitialized): Ooptionally use command-line arguments from the
UIProcess.
(WebCore::registerWebKitGStreamerElements): Decouple from initialization function.
(WebCore::initializeGStreamer): Deleted.
(WebCore::initializeGStreamerAndRegisterWebKitElements): Deleted.
* platform/graphics/gstreamer/GStreamerCommon.h:
* platform/graphics/gstreamer/GStreamerRegistryScanner.cpp:
(WebCore::GStreamerRegistryScanner::GStreamerRegistryScanner): Lazily initialize GStreamer.
* platform/graphics/gstreamer/ImageDecoderGStreamer.cpp:
(WebCore::ImageDecoderGStreamer::supportsContainerType): Bail off on non-video mime-types
and call-sites outside of the WebProcess. We can't rely on gst_is_initialized() anymore
because it is lazily initialized.
(WebCore::ImageDecoderGStreamer::canDecodeType): Ditto.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::isAvailable): This is a no-op now, no need to check
the playbin factory, we can fail from setPipeline().
(WebCore::MediaPlayerPrivateGStreamer::setPipeline): Bail off if playbin wasn't found.
(WebCore::MediaPlayerPrivateGStreamer::registerMediaEngine):
(WebCore::MediaPlayerPrivateGStreamer::loadFull): Remove now-useless gif hack, the player
discards all non-audio non-video mimetype.
(WebCore::MediaPlayerPrivateGStreamer::volumeChangedCallback): Prevent ghost volume notifications.
(WebCore::MediaPlayerPrivateGStreamer::supportsType): Bail off on image mime-types.
* platform/graphics/gstreamer/MediaSampleGStreamer.cpp:
(WebCore::MediaSampleGStreamer::createImageSample): Lazily initialize GStreamer.
* platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp:
(WebCore::MediaPlayerPrivateGStreamerMSE::registerMediaEngine): Simplify, isAvailable() now no-op.
* platform/mediastream/gstreamer/GStreamerAudioCaptureSource.cpp: Lazily initialize GStreamer.
(WebCore::initializeDebugCategory):
(WebCore::m_capturer):
(WebCore::GStreamerAudioCaptureSource::GStreamerAudioCaptureSource):
(WebCore::initializeGStreamerDebug): Deleted.
* platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp: Lazily initialize GStreamer.
(WebCore::GStreamerCaptureDeviceManager::captureDevices):
* platform/mediastream/gstreamer/GStreamerCapturer.cpp: Ditto.
(WebCore::initializeDebugCategory):
(WebCore::GStreamerCapturer::GStreamerCapturer):
(WebCore::initializeGStreamerAndDebug): Deleted.
* platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp: Ditto.
(WebCore::initializeDebugCategory):
(WebCore::GStreamerVideoCaptureSource::GStreamerVideoCaptureSource):
(WebCore::m_capturer):
(WebCore::initializeGStreamerDebug): Deleted.
* platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.cpp: Ditto.
(WebCore::MockRealtimeAudioSourceGStreamer::MockRealtimeAudioSourceGStreamer):
* platform/mediastream/gstreamer/MockRealtimeVideoSourceGStreamer.cpp: Ditto.
(WebCore::MockRealtimeVideoSourceGStreamer::MockRealtimeVideoSourceGStreamer):
* platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp: Ditto.
(WebCore::GStreamerVideoDecoderFactory::GStreamerVideoDecoderFactory):
* platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: Ditto.
(WebCore::GStreamerVideoEncoderFactory::GStreamerVideoEncoderFactory):

Source/WebKit:

Introduce a GTK/WPE UserMediaCaptureManager that relays permission requests to the
RealtimeMediaSourceCenter running in the WebProcess. We might move this to the GPUProcess at
some point but for the time being we only want to avoid initializing GStreamer from the
UIProcess.

* PlatformGTK.cmake:
* PlatformWPE.cmake:
* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
* UIProcess/glib/UserMediaPermissionRequestManagerProxyGLib.cpp: Added.
(WebKit::UserMediaPermissionRequestManagerProxy::processUserMediaPermissionRequest):
* WebProcess/glib/UserMediaCaptureManager.cpp: Added.
(WebKit::UserMediaCaptureManager::UserMediaCaptureManager):
(WebKit::UserMediaCaptureManager::~UserMediaCaptureManager):
(WebKit::UserMediaCaptureManager::validateUserMediaRequestConstraints):
* WebProcess/glib/UserMediaCaptureManager.h: Added.
(WebKit::UserMediaCaptureManager::supplementName):
* WebProcess/glib/UserMediaCaptureManager.messages.in: Added.
* WebProcess/glib/WebProcessGLib.cpp:
(WebKit::WebProcess::platformInitializeWebProcess):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271395 => 271396)


--- trunk/Source/WebCore/ChangeLog	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/ChangeLog	2021-01-12 10:55:16 UTC (rev 271396)
@@ -1,3 +1,77 @@
+2021-01-12  Philippe Normand  <[email protected]>
+
+        [GStreamer] Lazy initialization support
+        https://bugs.webkit.org/show_bug.cgi?id=209332
+
+        Reviewed by Carlos Garcia Campos.
+
+        The GStreamer library is now mostly used from the WebProcess only. The last remaining
+        GStreamer usage from the UIProcess is triggered by the webkit_web_view_can_show_mime_type()
+        API, which is acceptable for now.
+
+        GStreamer will now be initialized only if it is needed, so lazy initialization calls were
+        added in the various WebCore components relying on the library.
+
+        Based on preliminary patches by Charlie Turner <[email protected]> and Victor M Jaquez <[email protected]>.
+
+        * platform/audio/gstreamer/AudioDestinationGStreamer.cpp:
+        (WebCore::initializeDebugCategory): Lazily initialize GStreamer and load our in-house
+        elements (webkitwebaudiosrc is needed by this module).
+        * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp:
+        (WebCore::initializeDebugCategory): Lazily initialize GStreamer.
+        * platform/graphics/gstreamer/GStreamerCommon.cpp:
+        (WebCore::addGStreamerOptionsFromUIProcess): Store command-line arguments from the UIProcess.
+        (WebCore::ensureGStreamerInitialized): Ooptionally use command-line arguments from the
+        UIProcess.
+        (WebCore::registerWebKitGStreamerElements): Decouple from initialization function.
+        (WebCore::initializeGStreamer): Deleted.
+        (WebCore::initializeGStreamerAndRegisterWebKitElements): Deleted.
+        * platform/graphics/gstreamer/GStreamerCommon.h:
+        * platform/graphics/gstreamer/GStreamerRegistryScanner.cpp:
+        (WebCore::GStreamerRegistryScanner::GStreamerRegistryScanner): Lazily initialize GStreamer.
+        * platform/graphics/gstreamer/ImageDecoderGStreamer.cpp:
+        (WebCore::ImageDecoderGStreamer::supportsContainerType): Bail off on non-video mime-types
+        and call-sites outside of the WebProcess. We can't rely on gst_is_initialized() anymore
+        because it is lazily initialized.
+        (WebCore::ImageDecoderGStreamer::canDecodeType): Ditto.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::isAvailable): This is a no-op now, no need to check
+        the playbin factory, we can fail from setPipeline().
+        (WebCore::MediaPlayerPrivateGStreamer::setPipeline): Bail off if playbin wasn't found.
+        (WebCore::MediaPlayerPrivateGStreamer::registerMediaEngine):
+        (WebCore::MediaPlayerPrivateGStreamer::loadFull): Remove now-useless gif hack, the player
+        discards all non-audio non-video mimetype.
+        (WebCore::MediaPlayerPrivateGStreamer::volumeChangedCallback): Prevent ghost volume notifications.
+        (WebCore::MediaPlayerPrivateGStreamer::supportsType): Bail off on image mime-types.
+        * platform/graphics/gstreamer/MediaSampleGStreamer.cpp:
+        (WebCore::MediaSampleGStreamer::createImageSample): Lazily initialize GStreamer.
+        * platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp:
+        (WebCore::MediaPlayerPrivateGStreamerMSE::registerMediaEngine): Simplify, isAvailable() now no-op.
+        * platform/mediastream/gstreamer/GStreamerAudioCaptureSource.cpp: Lazily initialize GStreamer.
+        (WebCore::initializeDebugCategory):
+        (WebCore::m_capturer):
+        (WebCore::GStreamerAudioCaptureSource::GStreamerAudioCaptureSource):
+        (WebCore::initializeGStreamerDebug): Deleted.
+        * platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp: Lazily initialize GStreamer.
+        (WebCore::GStreamerCaptureDeviceManager::captureDevices):
+        * platform/mediastream/gstreamer/GStreamerCapturer.cpp: Ditto.
+        (WebCore::initializeDebugCategory):
+        (WebCore::GStreamerCapturer::GStreamerCapturer):
+        (WebCore::initializeGStreamerAndDebug): Deleted.
+        * platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp: Ditto.
+        (WebCore::initializeDebugCategory):
+        (WebCore::GStreamerVideoCaptureSource::GStreamerVideoCaptureSource):
+        (WebCore::m_capturer):
+        (WebCore::initializeGStreamerDebug): Deleted.
+        * platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.cpp: Ditto.
+        (WebCore::MockRealtimeAudioSourceGStreamer::MockRealtimeAudioSourceGStreamer):
+        * platform/mediastream/gstreamer/MockRealtimeVideoSourceGStreamer.cpp: Ditto.
+        (WebCore::MockRealtimeVideoSourceGStreamer::MockRealtimeVideoSourceGStreamer):
+        * platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp: Ditto.
+        (WebCore::GStreamerVideoDecoderFactory::GStreamerVideoDecoderFactory):
+        * platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp: Ditto.
+        (WebCore::GStreamerVideoEncoderFactory::GStreamerVideoEncoderFactory):
+
 2021-01-12  Zalan Bujtas  <[email protected]>
 
         [Multicol] set the childrenInline flag on the RenderBlockFlow properly

Modified: trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -44,6 +44,9 @@
 
 static void initializeDebugCategory()
 {
+    ensureGStreamerInitialized();
+    registerWebKitGStreamerElements();
+
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
         GST_DEBUG_CATEGORY_INIT(webkit_audio_destination_debug, "webkitaudiodestination", 0, "WebKit WebAudio Destination");

Modified: trunk/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -43,6 +43,7 @@
 
 static void initializeDebugCategory()
 {
+    ensureGStreamerInitialized();
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
         GST_DEBUG_CATEGORY_INIT(webkit_audio_file_reader_debug, "webkitaudiofilereader", 0, "WebKit WebAudio FileReader");

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -27,6 +27,7 @@
 #include "GStreamerAudioMixer.h"
 #include "GstAllocatorFastMalloc.h"
 #include "IntSize.h"
+#include "RuntimeApplicationChecks.h"
 #include "SharedBuffer.h"
 #include "WebKitAudioSinkGStreamer.h"
 #include <gst/audio/audio-info.h>
@@ -214,6 +215,12 @@
 #endif
 }
 
+static Optional<Vector<String>> s_UIProcessCommandLineOptions;
+void setGStreamerOptionsFromUIProcess(Vector<String>&& options)
+{
+    s_UIProcessCommandLineOptions = WTFMove(options);
+}
+
 Vector<String> extractGStreamerOptionsFromCommandLine()
 {
     GUniqueOutPtr<char> contents;
@@ -230,11 +237,12 @@
     return options;
 }
 
-bool initializeGStreamer(Optional<Vector<String>>&& options)
+bool ensureGStreamerInitialized()
 {
+    RELEASE_ASSERT(isInWebProcess());
     static std::once_flag onceFlag;
     static bool isGStreamerInitialized;
-    std::call_once(onceFlag, [options = WTFMove(options)] {
+    std::call_once(onceFlag, [] {
         isGStreamerInitialized = false;
 
         // USE_PLAYBIN3 is dangerous for us because its potential sneaky effect
@@ -245,7 +253,8 @@
             WTFLogAlways("The USE_PLAYBIN3 variable was detected in the environment. Expect playback issues or please unset it.");
 
 #if ENABLE(VIDEO) || ENABLE(WEB_AUDIO)
-        Vector<String> parameters = options.valueOr(extractGStreamerOptionsFromCommandLine());
+        Vector<String> parameters = s_UIProcessCommandLineOptions.valueOr(extractGStreamerOptionsFromCommandLine());
+        s_UIProcessCommandLineOptions.reset();
         char** argv = g_new0(char*, parameters.size() + 2);
         int argc = parameters.size() + 1;
         argv[0] = g_strdup(getCurrentExecutableName().data());
@@ -292,11 +301,8 @@
 }
 #endif
 
-bool initializeGStreamerAndRegisterWebKitElements()
+void registerWebKitGStreamerElements()
 {
-    if (!initializeGStreamer())
-        return false;
-
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
 #if USE(GSTREAMER_FULL)
@@ -343,7 +349,6 @@
             }
         }
     });
-    return true;
 }
 
 unsigned getGstPlayFlag(const char* nick)

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h (271395 => 271396)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h	2021-01-12 10:55:16 UTC (rev 271396)
@@ -69,8 +69,9 @@
 bool doCapsHaveType(const GstCaps*, const char*);
 bool areEncryptedCaps(const GstCaps*);
 Vector<String> extractGStreamerOptionsFromCommandLine();
-bool initializeGStreamer(Optional<Vector<String>>&& = WTF::nullopt);
-bool initializeGStreamerAndRegisterWebKitElements();
+void setGStreamerOptionsFromUIProcess(Vector<String>&&);
+bool ensureGStreamerInitialized();
+void registerWebKitGStreamerElements();
 unsigned getGstPlayFlag(const char* nick);
 uint64_t toGstUnsigned64Time(const MediaTime&);
 #if ENABLE(THUNDER)

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -183,8 +183,14 @@
 GStreamerRegistryScanner::GStreamerRegistryScanner(bool isMediaSource)
     : m_isMediaSource(isMediaSource)
 {
-    if (!isInWebProcess())
+    if (isInWebProcess())
+        ensureGStreamerInitialized();
+    else {
+        // This is still needed, mostly because of the webkit_web_view_can_show_mime_type() public API (so
+        // running from UIProcess).
         gst_init(nullptr, nullptr);
+    }
+
     GST_DEBUG_CATEGORY_INIT(webkit_media_gst_registry_scanner_debug, "webkitregistryscanner", 0, "WebKit GStreamer registry scanner");
 
     ElementFactories factories(OptionSet<ElementFactories::Type>::fromRaw(static_cast<unsigned>(ElementFactories::Type::All)));

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -28,6 +28,7 @@
 #include "ImageGStreamer.h"
 #include "MediaSampleGStreamer.h"
 #include "NotImplemented.h"
+#include "RuntimeApplicationChecks.h"
 #include <gst/app/gstappsink.h>
 #include <wtf/Lock.h>
 #include <wtf/MainThread.h>
@@ -100,22 +101,28 @@
 {
     // Ideally this decoder should operate only from the WebProcess (or from the GPUProcess) which
     // should be the only process where GStreamer has been runtime initialized.
-    if (!gst_is_initialized())
+    if (!isInWebProcess())
         return false;
 
+    if (!type.startsWith("video/"_s))
+        return false;
+
     return GStreamerRegistryScanner::singleton().isContainerTypeSupported(GStreamerRegistryScanner::Configuration::Decoding, type);
 }
 
 bool ImageDecoderGStreamer::canDecodeType(const String& mimeType)
 {
+    if (mimeType.isEmpty())
+        return false;
+
+    if (!mimeType.startsWith("video/"_s))
+        return false;
+
     // Ideally this decoder should operate only from the WebProcess (or from the GPUProcess) which
     // should be the only process where GStreamer has been runtime initialized.
-    if (!gst_is_initialized())
+    if (!isInWebProcess())
         return false;
 
-    if (mimeType.isEmpty())
-        return false;
-
     return GStreamerRegistryScanner::singleton().isContainerTypeSupported(GStreamerRegistryScanner::Configuration::Decoding, mimeType);
 }
 

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -303,14 +303,7 @@
 
 bool MediaPlayerPrivateGStreamer::isAvailable()
 {
-    if (!initializeGStreamerAndRegisterWebKitElements())
-        return false;
-
-    // FIXME: This has not been updated for the playbin3 switch.
-    GRefPtr<GstElementFactory> factory = adoptGRef(gst_element_factory_find("playbin"));
-    if (!factory)
-        GST_WARNING("Couldn't find a factory for the playbin element. Media playback will be disabled.");
-    return factory;
+    return true;
 }
 
 class MediaPlayerFactoryGStreamer final : public MediaPlayerFactory {
@@ -341,24 +334,24 @@
 void MediaPlayerPrivateGStreamer::registerMediaEngine(MediaEngineRegistrar registrar)
 {
     initializeDebugCategory();
-
-    if (isAvailable())
-        registrar(makeUnique<MediaPlayerFactoryGStreamer>());
+    registrar(makeUnique<MediaPlayerFactoryGStreamer>());
 }
 
 void MediaPlayerPrivateGStreamer::loadFull(const String& urlString, const String& pipelineName)
 {
-    if (m_player->contentMIMEType() == "image/gif") {
+    URL url(URL(), urlString);
+    if (url.protocolIsAbout()) {
         loadingFailed(MediaPlayer::NetworkState::FormatError, MediaPlayer::ReadyState::HaveNothing, true);
         return;
     }
 
-    URL url(URL(), urlString);
-    if (url.protocolIsAbout()) {
+    if (!ensureGStreamerInitialized()) {
         loadingFailed(MediaPlayer::NetworkState::FormatError, MediaPlayer::ReadyState::HaveNothing, true);
         return;
     }
 
+    registerWebKitGStreamerElements();
+
     if (!m_pipeline)
         createGSTPlayBin(url, pipelineName);
     syncOnClock(true);
@@ -1610,6 +1603,12 @@
 
 void MediaPlayerPrivateGStreamer::setPipeline(GstElement* pipeline)
 {
+    if (!pipeline) {
+        GST_WARNING("Playbin not found, make sure to install gst-plugins-base");
+        loadingFailed(MediaPlayer::NetworkState::FormatError, MediaPlayer::ReadyState::HaveNothing, true);
+        return;
+    }
+
     m_pipeline = pipeline;
 
     GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
@@ -1760,6 +1759,9 @@
 
 void MediaPlayerPrivateGStreamer::volumeChangedCallback(MediaPlayerPrivateGStreamer* player)
 {
+    if (player->isPlayerShuttingDown())
+        return;
+
     // This is called when m_volumeElement receives the notify::volume signal.
     GST_DEBUG_OBJECT(player->pipeline(), "Volume changed to: %f", player->volume());
 
@@ -2635,15 +2637,22 @@
         return result;
 #endif
 
-#if !ENABLE(MEDIA_STREAM)
-    if (parameters.isMediaStream)
+    if (parameters.isMediaStream) {
+#if ENABLE(MEDIA_STREAM)
+        return MediaPlayer::SupportsType::IsSupported;
+#else
         return result;
 #endif
+    }
 
+    GST_DEBUG("Checking mime-type \"%s\"", parameters.type.raw().utf8().data());
     if (parameters.type.isEmpty())
         return result;
 
-    GST_DEBUG("Checking mime-type \"%s\"", parameters.type.raw().utf8().data());
+    // This player doesn't support pictures rendering.
+    if (parameters.type.raw().startsWith("image"_s))
+        return result;
+
     auto& gstRegistryScanner = GStreamerRegistryScanner::singleton();
     result = gstRegistryScanner.isContentTypeSupported(GStreamerRegistryScanner::Configuration::Decoding, parameters.type, parameters.contentTypesRequiringHardwareSupport);
 

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaSampleGStreamer.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaSampleGStreamer.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaSampleGStreamer.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -99,6 +99,8 @@
 
 Ref<MediaSampleGStreamer> MediaSampleGStreamer::createImageSample(Vector<uint8_t>&& bgraData, unsigned width, unsigned height, double frameRate)
 {
+    ensureGStreamerInitialized();
+
     size_t size = bgraData.sizeInBytes();
     auto* data = ""
     auto buffer = adoptGRef(gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, data, size, 0, size, data, [](gpointer data) {

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -98,10 +98,8 @@
 
 void MediaPlayerPrivateGStreamerMSE::registerMediaEngine(MediaEngineRegistrar registrar)
 {
-    initializeGStreamerAndRegisterWebKitElements();
     GST_DEBUG_CATEGORY_INIT(webkit_mse_debug, "webkitmse", 0, "WebKit MSE media player");
-    if (isAvailable())
-        registrar(makeUnique<MediaPlayerFactoryGStreamerMSE>());
+    registrar(makeUnique<MediaPlayerFactoryGStreamerMSE>());
 }
 
 MediaPlayerPrivateGStreamerMSE::MediaPlayerPrivateGStreamerMSE(MediaPlayer* player)

Modified: trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCaptureSource.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCaptureSource.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCaptureSource.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -44,8 +44,10 @@
 GST_DEBUG_CATEGORY(webkit_audio_capture_source_debug);
 #define GST_CAT_DEFAULT webkit_audio_capture_source_debug
 
-static void initializeGStreamerDebug()
+static void initializeDebugCategory()
 {
+    ensureGStreamerInitialized();
+
     static std::once_flag debugRegisteredFlag;
     std::call_once(debugRegisteredFlag, [] {
         GST_DEBUG_CATEGORY_INIT(webkit_audio_capture_source_debug, "webkitaudiocapturesource", 0, "WebKit Audio Capture Source.");
@@ -97,7 +99,7 @@
     : RealtimeMediaSource(RealtimeMediaSource::Type::Audio, String { device.persistentId() }, String { device.label() }, WTFMove(hashSalt))
     , m_capturer(makeUnique<GStreamerAudioCapturer>(device))
 {
-    initializeGStreamerDebug();
+    initializeDebugCategory();
 }
 
 GStreamerAudioCaptureSource::GStreamerAudioCaptureSource(String&& deviceID, String&& name, String&& hashSalt)
@@ -104,7 +106,7 @@
     : RealtimeMediaSource(RealtimeMediaSource::Type::Audio, WTFMove(deviceID), WTFMove(name), WTFMove(hashSalt))
     , m_capturer(makeUnique<GStreamerAudioCapturer>())
 {
-    initializeGStreamerDebug();
+    initializeDebugCategory();
 }
 
 GStreamerAudioCaptureSource::~GStreamerAudioCaptureSource()

Modified: trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -79,7 +79,7 @@
 
 const Vector<CaptureDevice>& GStreamerCaptureDeviceManager::captureDevices()
 {
-    initializeGStreamer();
+    ensureGStreamerInitialized();
     if (m_devices.isEmpty())
         refreshCaptureDevices();
 

Modified: trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -34,9 +34,9 @@
 
 namespace WebCore {
 
-static void initializeGStreamerAndDebug()
+static void initializeDebugCategory()
 {
-    initializeGStreamer();
+    ensureGStreamerInitialized();
 
     static std::once_flag debugRegisteredFlag;
     std::call_once(debugRegisteredFlag, [] {
@@ -49,7 +49,7 @@
     , m_caps(caps)
     , m_sourceFactory(nullptr)
 {
-    initializeGStreamerAndDebug();
+    initializeDebugCategory();
 }
 
 GStreamerCapturer::GStreamerCapturer(const char* sourceFactory, GRefPtr<GstCaps> caps)
@@ -57,7 +57,7 @@
     , m_caps(caps)
     , m_sourceFactory(sourceFactory)
 {
-    initializeGStreamerAndDebug();
+    initializeDebugCategory();
 }
 
 GStreamerCapturer::~GStreamerCapturer()

Modified: trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -35,8 +35,10 @@
 GST_DEBUG_CATEGORY(webkit_video_capture_source_debug);
 #define GST_CAT_DEFAULT webkit_video_capture_source_debug
 
-static void initializeGStreamerDebug()
+static void initializeDebugCategory()
 {
+    ensureGStreamerInitialized();
+
     static std::once_flag debugRegisteredFlag;
     std::call_once(debugRegisteredFlag, [] {
         GST_DEBUG_CATEGORY_INIT(webkit_video_capture_source_debug, "webkitvideocapturesource", 0,
@@ -121,7 +123,7 @@
     : RealtimeVideoCaptureSource(WTFMove(deviceID), WTFMove(name), WTFMove(hashSalt))
     , m_capturer(makeUnique<GStreamerVideoCapturer>(source_factory))
 {
-    initializeGStreamerDebug();
+    initializeDebugCategory();
 }
 
 GStreamerVideoCaptureSource::GStreamerVideoCaptureSource(GStreamerCaptureDevice device, String&& hashSalt)
@@ -128,7 +130,7 @@
     : RealtimeVideoCaptureSource(String { device.persistentId() }, String { device.label() }, WTFMove(hashSalt))
     , m_capturer(makeUnique<GStreamerVideoCapturer>(device))
 {
-    initializeGStreamerDebug();
+    initializeDebugCategory();
 }
 
 GStreamerVideoCaptureSource::~GStreamerVideoCaptureSource()

Modified: trunk/Source/WebCore/platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -65,6 +65,7 @@
 MockRealtimeAudioSourceGStreamer::MockRealtimeAudioSourceGStreamer(String&& deviceID, String&& name, String&& hashSalt)
     : MockRealtimeAudioSource(WTFMove(deviceID), WTFMove(name), WTFMove(hashSalt))
 {
+    ensureGStreamerInitialized();
 }
 
 void MockRealtimeAudioSourceGStreamer::render(Seconds delta)

Modified: trunk/Source/WebCore/platform/mediastream/gstreamer/MockRealtimeVideoSourceGStreamer.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/mediastream/gstreamer/MockRealtimeVideoSourceGStreamer.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/MockRealtimeVideoSourceGStreamer.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -56,6 +56,7 @@
 MockRealtimeVideoSourceGStreamer::MockRealtimeVideoSourceGStreamer(String&& deviceID, String&& name, String&& hashSalt)
     : MockRealtimeVideoSource(WTFMove(deviceID), WTFMove(name), WTFMove(hashSalt))
 {
+    ensureGStreamerInitialized();
 }
 
 void MockRealtimeVideoSourceGStreamer::updateSampleBuffer()

Modified: trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -413,8 +413,9 @@
 
 GStreamerVideoDecoderFactory::GStreamerVideoDecoderFactory()
 {
+    ensureGStreamerInitialized();
+
     static std::once_flag debugRegisteredFlag;
-
     std::call_once(debugRegisteredFlag, [] {
         GST_DEBUG_CATEGORY_INIT(webkit_webrtcdec_debug, "webkitlibwebrtcvideodecoder", 0, "WebKit WebRTC video decoder");
     });

Modified: trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp (271395 => 271396)


--- trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoEncoderFactory.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -458,8 +458,9 @@
 
 GStreamerVideoEncoderFactory::GStreamerVideoEncoderFactory()
 {
+    ensureGStreamerInitialized();
+
     static std::once_flag debugRegisteredFlag;
-
     std::call_once(debugRegisteredFlag, [] {
         GST_DEBUG_CATEGORY_INIT(webkit_webrtcenc_debug, "webkitlibwebrtcvideoencoder", 0, "WebKit WebRTC video encoder");
         gst_element_register(nullptr, "webrtcvideoencoder", GST_RANK_NONE, WEBRTC_TYPE_VIDEO_ENCODER);

Modified: trunk/Source/WebKit/ChangeLog (271395 => 271396)


--- trunk/Source/WebKit/ChangeLog	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebKit/ChangeLog	2021-01-12 10:55:16 UTC (rev 271396)
@@ -1,3 +1,30 @@
+2021-01-12  Philippe Normand  <[email protected]>
+
+        [GStreamer] Lazy initialization support
+        https://bugs.webkit.org/show_bug.cgi?id=209332
+
+        Reviewed by Carlos Garcia Campos.
+
+        Introduce a GTK/WPE UserMediaCaptureManager that relays permission requests to the
+        RealtimeMediaSourceCenter running in the WebProcess. We might move this to the GPUProcess at
+        some point but for the time being we only want to avoid initializing GStreamer from the
+        UIProcess.
+
+        * PlatformGTK.cmake:
+        * PlatformWPE.cmake:
+        * UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
+        * UIProcess/glib/UserMediaPermissionRequestManagerProxyGLib.cpp: Added.
+        (WebKit::UserMediaPermissionRequestManagerProxy::processUserMediaPermissionRequest):
+        * WebProcess/glib/UserMediaCaptureManager.cpp: Added.
+        (WebKit::UserMediaCaptureManager::UserMediaCaptureManager):
+        (WebKit::UserMediaCaptureManager::~UserMediaCaptureManager):
+        (WebKit::UserMediaCaptureManager::validateUserMediaRequestConstraints):
+        * WebProcess/glib/UserMediaCaptureManager.h: Added.
+        (WebKit::UserMediaCaptureManager::supplementName):
+        * WebProcess/glib/UserMediaCaptureManager.messages.in: Added.
+        * WebProcess/glib/WebProcessGLib.cpp:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2021-01-12  Carlos Garcia Campos  <[email protected]>
 
         Unreviewed. Update OptionsGTK.cmake and NEWS for 2.31.1 release

Modified: trunk/Source/WebKit/PlatformGTK.cmake (271395 => 271396)


--- trunk/Source/WebKit/PlatformGTK.cmake	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebKit/PlatformGTK.cmake	2021-01-12 10:55:16 UTC (rev 271396)
@@ -428,6 +428,7 @@
     "${WEBKIT_DIR}/WebProcess/InjectedBundle/API/gtk"
     "${WEBKIT_DIR}/WebProcess/InjectedBundle/API/gtk/DOM"
     "${WEBKIT_DIR}/WebProcess/Inspector/gtk"
+    "${WEBKIT_DIR}/WebProcess/glib"
     "${WEBKIT_DIR}/WebProcess/gtk"
     "${WEBKIT_DIR}/WebProcess/soup"
     "${WEBKIT_DIR}/WebProcess/WebCoreSupport/gtk"
@@ -502,6 +503,17 @@
     )
 endif ()
 
+if (ENABLE_MEDIA_STREAM)
+    list(APPEND WebKit_SOURCES
+        UIProcess/glib/UserMediaPermissionRequestManagerProxyGLib.cpp
+
+        WebProcess/glib/UserMediaCaptureManager.cpp
+    )
+    list(APPEND WebKit_MESSAGES_IN_FILES
+        WebProcess/glib/UserMediaCaptureManager
+    )
+endif ()
+
 # To generate WebKitEnumTypes.h we want to use all installed headers, except WebKitEnumTypes.h itself.
 set(WebKit2GTK_ENUM_GENERATION_HEADERS ${WebKit2GTK_INSTALLED_HEADERS})
 list(REMOVE_ITEM WebKit2GTK_ENUM_GENERATION_HEADERS ${DERIVED_SOURCES_WEBKIT2GTK_API_DIR}/WebKitEnumTypes.h)

Modified: trunk/Source/WebKit/PlatformWPE.cmake (271395 => 271396)


--- trunk/Source/WebKit/PlatformWPE.cmake	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebKit/PlatformWPE.cmake	2021-01-12 10:55:16 UTC (rev 271396)
@@ -265,6 +265,7 @@
     "${WEBKIT_DIR}/WebProcess/InjectedBundle/API/glib/DOM"
     "${WEBKIT_DIR}/WebProcess/InjectedBundle/API/wpe"
     "${WEBKIT_DIR}/WebProcess/InjectedBundle/API/wpe/DOM"
+    "${WEBKIT_DIR}/WebProcess/glib"
     "${WEBKIT_DIR}/WebProcess/soup"
     "${WEBKIT_DIR}/WebProcess/WebCoreSupport/soup"
     "${WEBKIT_DIR}/WebProcess/WebPage/CoordinatedGraphics"
@@ -322,6 +323,17 @@
     )
 endif ()
 
+if (ENABLE_MEDIA_STREAM)
+    list(APPEND WebKit_SOURCES
+        UIProcess/glib/UserMediaPermissionRequestManagerProxyGLib.cpp
+
+        WebProcess/glib/UserMediaCaptureManager.cpp
+    )
+    list(APPEND WebKit_MESSAGES_IN_FILES
+        WebProcess/glib/UserMediaCaptureManager
+    )
+endif ()
+
 WEBKIT_BUILD_INSPECTOR_GRESOURCES(${WebInspectorUI_DERIVED_SOURCES_DIR})
 list(APPEND WPEWebInspectorResources_DERIVED_SOURCES
     ${WebInspectorUI_DERIVED_SOURCES_DIR}/InspectorGResourceBundle.c

Modified: trunk/Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp (271395 => 271396)


--- trunk/Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -504,12 +504,17 @@
 
         syncWithWebCorePrefs();
 
-        RealtimeMediaSourceCenter::singleton().validateRequestConstraints(WTFMove(validHandler), WTFMove(invalidHandler), m_currentUserMediaRequest->userRequest(), WTFMove(deviceIDHashSalt));
+        platformValidateUserMediaRequestConstraints(WTFMove(validHandler), WTFMove(invalidHandler), WTFMove(deviceIDHashSalt));
     });
 }
+
+#if ENABLE(MEDIA_STREAM) && !USE(GLIB)
+void UserMediaPermissionRequestManagerProxy::platformValidateUserMediaRequestConstraints(WebCore::RealtimeMediaSourceCenter::ValidConstraintsHandler&& validHandler, RealtimeMediaSourceCenter::InvalidConstraintsHandler&& invalidHandler, String&& deviceIDHashSalt)
+{
+    RealtimeMediaSourceCenter::singleton().validateRequestConstraints(WTFMove(validHandler), WTFMove(invalidHandler), m_currentUserMediaRequest->userRequest(), WTFMove(deviceIDHashSalt));
+}
 #endif
 
-#if ENABLE(MEDIA_STREAM)
 void UserMediaPermissionRequestManagerProxy::processUserMediaPermissionInvalidRequest(const String& invalidConstraint)
 {
     ALWAYS_LOG(LOGIDENTIFIER, m_currentUserMediaRequest->userMediaID());

Modified: trunk/Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h (271395 => 271396)


--- trunk/Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h	2021-01-12 10:55:16 UTC (rev 271396)
@@ -22,6 +22,7 @@
 #include "UserMediaPermissionCheckProxy.h"
 #include "UserMediaPermissionRequestProxy.h"
 #include <WebCore/MediaProducer.h>
+#include <WebCore/RealtimeMediaSourceCenter.h>
 #include <WebCore/RealtimeMediaSourceFactory.h>
 #include <WebCore/SecurityOrigin.h>
 #include <wtf/CompletionHandler.h>
@@ -129,6 +130,10 @@
     static void requestSystemValidation(const WebPageProxy&, UserMediaPermissionRequestProxy&, CompletionHandler<void(bool)>&&);
 #endif
 
+#if ENABLE(MEDIA_STREAM)
+    void platformValidateUserMediaRequestConstraints(WebCore::RealtimeMediaSourceCenter::ValidConstraintsHandler&& validHandler, WebCore::RealtimeMediaSourceCenter::InvalidConstraintsHandler&& invalidHandler, String&& deviceIDHashSalt);
+#endif
+
     void watchdogTimerFired();
 
     void processNextUserMediaRequestIfNeeded();

Added: trunk/Source/WebKit/UIProcess/glib/UserMediaPermissionRequestManagerProxyGLib.cpp (0 => 271396)


--- trunk/Source/WebKit/UIProcess/glib/UserMediaPermissionRequestManagerProxyGLib.cpp	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/glib/UserMediaPermissionRequestManagerProxyGLib.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2020 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "UserMediaPermissionRequestManagerProxy.h"
+
+#include "DeviceIdHashSaltStorage.h"
+#include "Logging.h"
+#include "UserMediaCaptureManagerMessages.h"
+#include "WebPageProxy.h"
+#include "WebProcess.h"
+#include "WebProcessProxy.h"
+#include "WebsiteDataStore.h"
+#include <WebCore/UserMediaRequest.h>
+
+namespace WebKit {
+using namespace WebCore;
+
+void UserMediaPermissionRequestManagerProxy::platformValidateUserMediaRequestConstraints(RealtimeMediaSourceCenter::ValidConstraintsHandler&& validHandler, RealtimeMediaSourceCenter::InvalidConstraintsHandler&& invalidHandler, String&& deviceIDHashSalt)
+{
+    m_page.process().connection()->sendWithAsyncReply(Messages::UserMediaCaptureManager::ValidateUserMediaRequestConstraints(m_currentUserMediaRequest->userRequest(), deviceIDHashSalt), [validHandler = WTFMove(validHandler), invalidHandler = WTFMove(invalidHandler)](Optional<String> invalidConstraint, Vector<WebCore::CaptureDevice> audioDevices, Vector<WebCore::CaptureDevice> videoDevices, Optional<String> deviceIdentifierHashSalt) mutable {
+        if (invalidConstraint.hasValue())
+            invalidHandler(*invalidConstraint);
+        else
+            validHandler(WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(*deviceIdentifierHashSalt));
+    });
+}
+
+} // namespace WebKit

Added: trunk/Source/WebKit/WebProcess/glib/UserMediaCaptureManager.cpp (0 => 271396)


--- trunk/Source/WebKit/WebProcess/glib/UserMediaCaptureManager.cpp	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/glib/UserMediaCaptureManager.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2020 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "UserMediaCaptureManager.h"
+
+#if USE(GLIB) && ENABLE(MEDIA_STREAM)
+
+#include "UserMediaCaptureManagerMessages.h"
+#include "WebProcess.h"
+#include <WebCore/CaptureDevice.h>
+#include <WebCore/MediaStreamRequest.h>
+#include <WebCore/RealtimeMediaSourceCenter.h>
+
+namespace WebKit {
+using namespace WebCore;
+
+UserMediaCaptureManager::UserMediaCaptureManager(WebProcess& process)
+    : m_process(process)
+{
+    m_process.addMessageReceiver(Messages::UserMediaCaptureManager::messageReceiverName(), *this);
+}
+
+UserMediaCaptureManager::~UserMediaCaptureManager()
+{
+    m_process.removeMessageReceiver(Messages::UserMediaCaptureManager::messageReceiverName());
+}
+
+void UserMediaCaptureManager::validateUserMediaRequestConstraints(WebCore::MediaStreamRequest request, String hashSalt, ValidateUserMediaRequestConstraintsCallback&& completionHandler)
+{
+    m_validateUserMediaRequestConstraintsCallback = WTFMove(completionHandler);
+    RealtimeMediaSourceCenter::InvalidConstraintsHandler invalidHandler = [this](const String& invalidConstraint) mutable {
+        Vector<CaptureDevice> audioDevices;
+        Vector<CaptureDevice> videoDevices;
+        m_validateUserMediaRequestConstraintsCallback(invalidConstraint, audioDevices, videoDevices, { });
+    };
+
+    auto validHandler = [this](Vector<CaptureDevice>&& audioDevices, Vector<CaptureDevice>&& videoDevices, String&& deviceIdentifierHashSalt) mutable {
+        m_validateUserMediaRequestConstraintsCallback(WTF::nullopt, audioDevices, videoDevices, deviceIdentifierHashSalt);
+    };
+
+    RealtimeMediaSourceCenter::singleton().validateRequestConstraints(WTFMove(validHandler), WTFMove(invalidHandler), request, WTFMove(hashSalt));
+}
+
+}
+
+#endif

Added: trunk/Source/WebKit/WebProcess/glib/UserMediaCaptureManager.h (0 => 271396)


--- trunk/Source/WebKit/WebProcess/glib/UserMediaCaptureManager.h	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/glib/UserMediaCaptureManager.h	2021-01-12 10:55:16 UTC (rev 271396)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2020 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(GLIB) && ENABLE(MEDIA_STREAM)
+
+#include "MessageReceiver.h"
+#include "WebProcessSupplement.h"
+#include <wtf/CompletionHandler.h>
+
+namespace WebCore {
+class CaptureDevice;
+struct MediaStreamRequest;
+}
+
+namespace WebKit {
+
+class WebProcess;
+
+class UserMediaCaptureManager : public WebProcessSupplement, public IPC::MessageReceiver {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    explicit UserMediaCaptureManager(WebProcess&);
+    ~UserMediaCaptureManager();
+
+    static const char* supplementName() { return "UserMediaCaptureManager"; }
+
+private:
+    // IPC::MessageReceiver
+    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
+
+    // Messages::UserMediaCaptureManager
+    using ValidateUserMediaRequestConstraintsCallback = CompletionHandler<void(Optional<String> invalidConstraint, Vector<WebCore::CaptureDevice>& audioDevices, Vector<WebCore::CaptureDevice>& videoDevices, Optional<String> deviceIdentifierHashSalt)>;
+    void validateUserMediaRequestConstraints(WebCore::MediaStreamRequest, String hashSalt, ValidateUserMediaRequestConstraintsCallback&&);
+    ValidateUserMediaRequestConstraintsCallback m_validateUserMediaRequestConstraintsCallback;
+
+    WebProcess& m_process;
+};
+
+} // namespace WebKit
+
+#endif

Added: trunk/Source/WebKit/WebProcess/glib/UserMediaCaptureManager.messages.in (0 => 271396)


--- trunk/Source/WebKit/WebProcess/glib/UserMediaCaptureManager.messages.in	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/glib/UserMediaCaptureManager.messages.in	2021-01-12 10:55:16 UTC (rev 271396)
@@ -0,0 +1,30 @@
+# Copyright (C) 2020 Igalia S.L.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+# THE POSSIBILITY OF SUCH DAMAGE.
+
+#if ENABLE(MEDIA_STREAM)
+
+messages -> UserMediaCaptureManager NotRefCounted {
+    ValidateUserMediaRequestConstraints(struct WebCore::MediaStreamRequest request, String hashSalt) -> (Optional<String> invalidConstraint, Vector<WebCore::CaptureDevice> audioDevices, Vector<WebCore::CaptureDevice> videoDevices, Optional<String> deviceIdentifierHashSalt) Async
+}
+
+#endif

Modified: trunk/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp (271395 => 271396)


--- trunk/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp	2021-01-12 10:42:26 UTC (rev 271395)
+++ trunk/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp	2021-01-12 10:55:16 UTC (rev 271396)
@@ -50,6 +50,10 @@
 #include <WebCore/ScrollbarThemeGtk.h>
 #endif
 
+#if ENABLE(MEDIA_STREAM)
+#include "UserMediaCaptureManager.h"
+#endif
+
 namespace WebKit {
 
 using namespace WebCore;
@@ -61,6 +65,10 @@
 
 void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
 {
+#if ENABLE(MEDIA_STREAM)
+    addSupplement<UserMediaCaptureManager>();
+#endif
+
 #if PLATFORM(WPE)
     if (!parameters.isServiceWorkerProcess) {
         auto& implementationLibraryName = parameters.implementationLibraryName;
@@ -91,7 +99,7 @@
 #endif
 
 #if USE(GSTREAMER)
-    WebCore::initializeGStreamer(WTFMove(parameters.gstreamerOptions));
+    WebCore::setGStreamerOptionsFromUIProcess(WTFMove(parameters.gstreamerOptions));
 #endif
 
 #if PLATFORM(GTK) && !USE(GTK4)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to