wpe: Emit load-progress messages
authorPhilippe Normand <philn@igalia.com>
Mon, 19 Oct 2020 13:56:43 +0000 (14:56 +0100)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 9 Dec 2020 17:31:51 +0000 (17:31 +0000)
The estimated-load-progress value can be used on application side to display a
progress bar for instance.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1710>

ext/wpe/WPEThreadedView.cpp
ext/wpe/gstwpesrc.cpp

index d95c298..9af1e2d 100644 (file)
@@ -205,6 +205,20 @@ static gboolean s_loadFailedWithTLSErrors(WebKitWebView*,  gchar* failing_uri, G
     return FALSE;
 }
 
+static void s_loadProgressChaned(GObject* object, GParamSpec*, gpointer data)
+{
+    GstElement* src = GST_ELEMENT_CAST (data);
+    // The src element is locked already so we can't call
+    // gst_element_post_message(). Instead retrieve the bus manually and use it
+    // directly.
+    GstBus* bus = GST_ELEMENT_BUS (src);
+    double estimatedProgress;
+    g_object_get(object, "estimated-load-progress", &estimatedProgress, nullptr);
+    gst_object_ref (bus);
+    gst_bus_post (bus, gst_message_new_element(GST_OBJECT_CAST(src), gst_structure_new("wpe-stats", "estimated-load-progress", G_TYPE_DOUBLE, estimatedProgress * 100, nullptr)));
+    gst_object_unref (bus);
+}
+
 WPEView::WPEView(WebKitWebContext* web_context, GstWpeSrc* src, GstGLContext* context, GstGLDisplay* display, int width, int height)
 {
     g_mutex_init(&threading.ready_mutex);
@@ -264,6 +278,7 @@ WPEView::WPEView(WebKitWebContext* web_context, GstWpeSrc* src, GstGLContext* co
 
     g_signal_connect(webkit.view, "load-failed", G_CALLBACK(s_loadFailed), src);
     g_signal_connect(webkit.view, "load-failed-with-tls-errors", G_CALLBACK(s_loadFailedWithTLSErrors), src);
+    g_signal_connect(webkit.view, "notify::estimated-load-progress", G_CALLBACK(s_loadProgressChaned), src);
 
     gst_wpe_src_configure_web_view(src, webkit.view);
 
index 6ee15cb..9b824cf 100644 (file)
  * variable and make sure `video/x-raw, format=BGRA` caps are negotiated by the
  * wpesrc element.
  *
+ * As the webview loading is usually not instantaneous, the wpesrc element emits
+ * messages indicating the load progress, in percent. The value is an estimate
+ * based on the total number of bytes expected to be received for a document,
+ * including all its possible subresources and child documents. The application
+ * can handle these `element` messages synchronously for instance, in order to
+ * display a progress bar or other visual load indicator. The load percent value
+ * is stored in the message structure as a double value named
+ * `estimated-load-progress` and the structure name is `wpe-stats`.
+ *
  * ## Example launch lines
  *
  * ```shell