From 3bcb876c29bb9da233f1db71714da75d7abd8916 Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Mon, 19 Oct 2020 14:56:43 +0100 Subject: [PATCH] wpe: Emit load-progress messages The estimated-load-progress value can be used on application side to display a progress bar for instance. Part-of: --- ext/wpe/WPEThreadedView.cpp | 15 +++++++++++++++ ext/wpe/gstwpesrc.cpp | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/ext/wpe/WPEThreadedView.cpp b/ext/wpe/WPEThreadedView.cpp index d95c298..9af1e2d 100644 --- a/ext/wpe/WPEThreadedView.cpp +++ b/ext/wpe/WPEThreadedView.cpp @@ -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); diff --git a/ext/wpe/gstwpesrc.cpp b/ext/wpe/gstwpesrc.cpp index 6ee15cb..9b824cf 100644 --- a/ext/wpe/gstwpesrc.cpp +++ b/ext/wpe/gstwpesrc.cpp @@ -30,6 +30,15 @@ * 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 -- 2.7.4