[GStreamer][WebRTC] Add API to enable/disable device mocks
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2018 14:09:39 +0000 (14:09 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2018 14:09:39 +0000 (14:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191699

This basically us to test MediaStream/WebRTC support without
requiring cameras or microphones and is quite useful.

Also fix the GStreamerAudioMock by:
  - Stop setting `leaky-upstream` on the GStreamerCapturer queue,
    this was usefull when we were trying to bring the MediaStream
    sources inside the main pipeline, it is not the case anymore
    (and not doable with latest version of LibWebRTC).
  - Use a 'ticks' wave on the gstreamer audiotestsrc so the test
    stream is similar to what Apple port does.

Patch by Thibault Saunier <tsaunier@igalia.com> on 2018-11-16
Reviewed by Xabier Rodriguez-Calvar.

The mocks are already tested and the API is really simple.

Source/WebCore:

* platform/mediastream/gstreamer/GStreamerAudioCapturer.cpp:
(WebCore::GStreamerAudioCapturer::createSource):
* platform/mediastream/gstreamer/GStreamerAudioCapturer.h:
* platform/mediastream/gstreamer/GStreamerCapturer.cpp:
(WebCore::GStreamerCapturer::addSink):
* platform/mediastream/gstreamer/GStreamerCapturer.h:

Source/WebKit:

* UIProcess/API/glib/WebKitSettings.cpp:
(webKitSettingsSetProperty):
(webKitSettingsGetProperty):
(webkit_settings_class_init):
(webkit_settings_get_enable_mock_capture_devices):
(webkit_settings_set_enable_mock_capture_devices):
* UIProcess/API/gtk/WebKitSettings.h:
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238278 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCapturer.cpp
Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCapturer.h
Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp
Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp
Source/WebKit/UIProcess/API/gtk/WebKitSettings.h
Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
Source/WebKit/UIProcess/API/wpe/WebKitSettings.h

index 893e307..59e20a5 100644 (file)
@@ -1,5 +1,32 @@
 2018-11-16  Thibault Saunier  <tsaunier@igalia.com>
 
+        [GStreamer][WebRTC] Add API to enable/disable device mocks
+        https://bugs.webkit.org/show_bug.cgi?id=191699
+
+        This basically us to test MediaStream/WebRTC support without
+        requiring cameras or microphones and is quite useful.
+
+        Also fix the GStreamerAudioMock by:
+          - Stop setting `leaky-upstream` on the GStreamerCapturer queue,
+            this was usefull when we were trying to bring the MediaStream
+            sources inside the main pipeline, it is not the case anymore
+            (and not doable with latest version of LibWebRTC).
+          - Use a 'ticks' wave on the gstreamer audiotestsrc so the test
+            stream is similar to what Apple port does.
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        The mocks are already tested and the API is really simple.
+
+        * platform/mediastream/gstreamer/GStreamerAudioCapturer.cpp:
+        (WebCore::GStreamerAudioCapturer::createSource):
+        * platform/mediastream/gstreamer/GStreamerAudioCapturer.h:
+        * platform/mediastream/gstreamer/GStreamerCapturer.cpp:
+        (WebCore::GStreamerCapturer::addSink):
+        * platform/mediastream/gstreamer/GStreamerCapturer.h:
+
+2018-11-16  Thibault Saunier  <tsaunier@igalia.com>
+
         [GStreamer][MediaStream] Handle track addition and removal
         https://bugs.webkit.org/show_bug.cgi?id=191599
 
index 64157ef..8df758a 100644 (file)
@@ -40,6 +40,16 @@ GStreamerAudioCapturer::GStreamerAudioCapturer()
 {
 }
 
+GstElement* GStreamerAudioCapturer::createSource()
+{
+    GstElement* source = GStreamerCapturer::createSource();
+
+    if (!m_device)
+        gst_util_set_object_arg(G_OBJECT(m_src.get()), "wave", "ticks");
+
+    return source;
+}
+
 GstElement* GStreamerAudioCapturer::createConverter()
 {
     auto converter = gst_parse_bin_from_description("audioconvert ! audioresample", TRUE, nullptr);
index 9aaf761..7b279ee 100644 (file)
@@ -32,6 +32,7 @@ public:
     GStreamerAudioCapturer(GStreamerCaptureDevice);
     GStreamerAudioCapturer();
 
+    GstElement* createSource() final;
     GstElement* createConverter() final;
     const char* name() final { return "Audio"; }
 
index 92bfa41..2933eea 100644 (file)
@@ -155,13 +155,6 @@ void GStreamerCapturer::addSink(GstElement* newSink)
         return;
     }
 
-    if (newSink == m_sink.get()) {
-        GST_INFO_OBJECT(m_pipeline.get(), "Setting queue as leaky upstream"
-            " so that the player can set the sink to PAUSED without "
-            " setting the whole capturer to PAUSED");
-        g_object_set(queue, "leaky", 2 /* upstream */, nullptr);
-    }
-
     GST_INFO_OBJECT(pipeline(), "Adding sink: %" GST_PTR_FORMAT, newSink);
 
     GUniquePtr<char> dumpName(g_strdup_printf("%s_sink_%s_added", GST_OBJECT_NAME(pipeline()), GST_OBJECT_NAME(newSink)));
index 7bfceda..bbe5ae7 100644 (file)
@@ -43,7 +43,7 @@ public:
     GstCaps* caps();
     void addSink(GstElement *newSink);
     GstElement* makeElement(const char* factoryName);
-    GstElement* createSource();
+    virtual GstElement* createSource();
     GstElement* source() { return m_src.get();  }
     virtual const char* name() = 0;
 
index 95b080b..c08a631 100644 (file)
@@ -1,5 +1,34 @@
 2018-11-16  Thibault Saunier  <tsaunier@igalia.com>
 
+        [GStreamer][WebRTC] Add API to enable/disable device mocks
+        https://bugs.webkit.org/show_bug.cgi?id=191699
+
+        This basically us to test MediaStream/WebRTC support without
+        requiring cameras or microphones and is quite useful.
+
+        Also fix the GStreamerAudioMock by:
+          - Stop setting `leaky-upstream` on the GStreamerCapturer queue,
+            this was usefull when we were trying to bring the MediaStream
+            sources inside the main pipeline, it is not the case anymore
+            (and not doable with latest version of LibWebRTC).
+          - Use a 'ticks' wave on the gstreamer audiotestsrc so the test
+            stream is similar to what Apple port does.
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        The mocks are already tested and the API is really simple.
+
+        * UIProcess/API/glib/WebKitSettings.cpp:
+        (webKitSettingsSetProperty):
+        (webKitSettingsGetProperty):
+        (webkit_settings_class_init):
+        (webkit_settings_get_enable_mock_capture_devices):
+        (webkit_settings_set_enable_mock_capture_devices):
+        * UIProcess/API/gtk/WebKitSettings.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+
+2018-11-16  Thibault Saunier  <tsaunier@igalia.com>
+
         [GTK][WPE] Add "WebKitDeviceInfoPermissionRequest.h" into webkit2.h
         https://bugs.webkit.org/show_bug.cgi?id=191744
 
index 3fc40e2..9819d91 100644 (file)
@@ -152,6 +152,7 @@ enum {
     PROP_ENABLE_ACCELERATED_2D_CANVAS,
     PROP_ENABLE_WRITE_CONSOLE_MESSAGES_TO_STDOUT,
     PROP_ENABLE_MEDIA_STREAM,
+    PROP_ENABLE_MOCK_CAPTURE_DEVICES,
     PROP_ENABLE_SPATIAL_NAVIGATION,
     PROP_ENABLE_MEDIASOURCE,
     PROP_ENABLE_ENCRYPTED_MEDIA,
@@ -352,6 +353,9 @@ static void webKitSettingsSetProperty(GObject* object, guint propId, const GValu
     case PROP_ENABLE_MEDIA_STREAM:
         webkit_settings_set_enable_media_stream(settings, g_value_get_boolean(value));
         break;
+    case PROP_ENABLE_MOCK_CAPTURE_DEVICES:
+        webkit_settings_set_enable_mock_capture_devices(settings, g_value_get_boolean(value));
+        break;
     case PROP_ENABLE_SPATIAL_NAVIGATION:
         webkit_settings_set_enable_spatial_navigation(settings, g_value_get_boolean(value));
         break;
@@ -528,6 +532,9 @@ static void webKitSettingsGetProperty(GObject* object, guint propId, GValue* val
     case PROP_ENABLE_MEDIA_STREAM:
         g_value_set_boolean(value, webkit_settings_get_enable_media_stream(settings));
         break;
+    case PROP_ENABLE_MOCK_CAPTURE_DEVICES:
+        g_value_set_boolean(value, webkit_settings_get_enable_mock_capture_devices(settings));
+        break;
     case PROP_ENABLE_SPATIAL_NAVIGATION:
         g_value_set_boolean(value, webkit_settings_get_enable_spatial_navigation(settings));
         break;
@@ -1269,6 +1276,23 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass)
             FALSE,
             readWriteConstructParamFlags));
 
+    /**
+     * WebKitSettings:enable-mock-capture-devices:
+     *
+     * Enable or disable the Mock Capture Devices. Those are fake
+     * Microphone and Camera devices to be used as MediaStream
+     * sources.
+     *
+     * Since: 2.24
+     */
+    g_object_class_install_property(gObjectClass,
+        PROP_ENABLE_MOCK_CAPTURE_DEVICES,
+        g_param_spec_boolean("enable-mock-capture-devices",
+            _("Enable mock capture devices"),
+            _("Whether we expose mock capture devices or not"),
+            FALSE,
+            readWriteConstructParamFlags));
+
    /**
      * WebKitSettings:enable-spatial-navigation:
      *
@@ -3128,6 +3152,45 @@ void webkit_settings_set_enable_media_stream(WebKitSettings* settings, gboolean
 }
 
 /**
+ * webkit_settings_get_enable_mock_capture_devices:
+ * @settings: a #WebKitSettings
+ *
+ * Get the #WebKitSettings:enable-mock-capture-devices property.
+ *
+ * Returns: %TRUE If mock capture devices is enabled or %FALSE otherwise.
+ *
+ * Since: 2.24
+ */
+gboolean webkit_settings_get_enable_mock_capture_devices(WebKitSettings* settings)
+{
+    g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE);
+
+    return settings->priv->preferences->mockCaptureDevicesEnabled();
+}
+
+/**
+ * webkit_settings_set_enable_mock_capture_devices:
+ * @settings: a #WebKitSettings
+ * @enabled: Value to be set
+ *
+ * Set the #WebKitSettings:enable-mock-capture-devices property.
+ *
+ * Since: 2.4
+ */
+void webkit_settings_set_enable_mock_capture_devices(WebKitSettings* settings, gboolean enabled)
+{
+    g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
+
+    WebKitSettingsPrivate* priv = settings->priv;
+    bool currentValue = priv->preferences->mockCaptureDevicesEnabled();
+    if (currentValue == enabled)
+        return;
+
+    priv->preferences->setMockCaptureDevicesEnabled(enabled);
+    g_object_notify(G_OBJECT(settings), "enable-mock-capture-devices");
+}
+
+/**
  * webkit_settings_set_enable_spatial_navigation:
  * @settings: a #WebKitSettings
  * @enabled: Value to be set
index 84999ed..cb2c206 100644 (file)
@@ -417,6 +417,13 @@ webkit_settings_set_enable_media_stream                        (WebKitSettings *
                                                                 gboolean        enabled);
 
 WEBKIT_API gboolean
+webkit_settings_get_enable_mock_capture_devices                (WebKitSettings *settings);
+
+WEBKIT_API void
+webkit_settings_set_enable_mock_capture_devices                (WebKitSettings *settings,
+                                                                gboolean        enabled);
+
+WEBKIT_API gboolean
 webkit_settings_get_enable_spatial_navigation                  (WebKitSettings *settings);
 
 WEBKIT_API void
index b724c0d..0afe2b3 100644 (file)
@@ -471,6 +471,8 @@ webkit_settings_get_enable_write_console_messages_to_stdout
 webkit_settings_set_enable_write_console_messages_to_stdout
 webkit_settings_get_enable_media_stream
 webkit_settings_set_enable_media_stream
+webkit_settings_get_enable_mock_capture_devices
+webkit_settings_set_enable_mock_capture_devices
 webkit_settings_get_enable_spatial_navigation
 webkit_settings_set_enable_spatial_navigation
 webkit_settings_get_enable_mediasource
index c8b1d82..2ec0c9e 100644 (file)
@@ -394,6 +394,13 @@ webkit_settings_set_enable_media_stream                        (WebKitSettings *
                                                                 gboolean        enabled);
 
 WEBKIT_API gboolean
+webkit_settings_get_enable_mock_capture_devices                (WebKitSettings *settings);
+
+WEBKIT_API void
+webkit_settings_set_enable_mock_capture_devices                (WebKitSettings *settings,
+                                                                gboolean        enabled);
+
+WEBKIT_API gboolean
 webkit_settings_get_enable_spatial_navigation                  (WebKitSettings *settings);
 
 WEBKIT_API void