wpe: Make forwarded messages layout more like GstBinForwaded messages
authorThibault Saunier <tsaunier@igalia.com>
Wed, 26 May 2021 03:58:27 +0000 (23:58 -0400)
committerThibault Saunier <tsaunier@igalia.com>
Tue, 8 Jun 2021 03:15:05 +0000 (03:15 +0000)
Making it look more like how we do this kind of things in other places.

See: https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2252#note_927653
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2273>

ext/wpe/WPEThreadedView.cpp
ext/wpe/gstwpesrcbin.cpp
ext/wpe/wpe-extension/gstwpebusmsgforwarder.c

index b4a49b4..7d1e5f2 100644 (file)
@@ -167,12 +167,16 @@ initialize_web_extensions (WebKitWebContext *context)
 static void
 webkit_extension_gerror_msg_received (GstWpeSrc *src, GVariant *params)
 {
-    GstMessage *message;
-    const gchar *message_type, *src_path, *error_domain, *msg, *debug_str, *details_str;
+    GstStructure *structure;
+    GstMessage *forwarded;
+    const gchar *src_path, *src_type, *src_name, *error_domain, *msg, *debug_str, *details_str;
+    gint message_type;
     guint32 error_code;
 
-    g_variant_get (params, "(sssusss)",
+    g_variant_get (params, "(issssusss)",
        &message_type,
+       &src_type,
+       &src_name,
        &src_path,
        &error_domain,
        &error_code,
@@ -188,37 +192,44 @@ webkit_extension_gerror_msg_received (GstWpeSrc *src, GVariant *params)
         debug_str, src_path
     );
 
-    if (!details)
-        details = gst_structure_new_empty("wpesrcdetails");
-    gst_structure_set(details,
-                      "wpesrc_original_src_path", G_TYPE_STRING, src_path,
-                      NULL);
 
-    if (!g_strcmp0(message_type, "error")) {
-        message =
+    if (message_type == GST_MESSAGE_ERROR) {
+        forwarded =
             gst_message_new_error_with_details(GST_OBJECT(src), error,
                                                our_message, details);
-    } else if (!g_strcmp0(message_type, "warning")) {
-        message =
+    } else if (message_type == GST_MESSAGE_WARNING) {
+        forwarded =
             gst_message_new_warning_with_details(GST_OBJECT(src), error,
                                                  our_message, details);
     } else {
-        message =
+        forwarded =
             gst_message_new_info_with_details(GST_OBJECT(src), error, our_message, details);
     }
 
+    structure = gst_structure_new ("WpeForwarded",
+        "message", GST_TYPE_MESSAGE, forwarded,
+        "wpe-original-src-name", G_TYPE_STRING, src_name,
+        "wpe-original-src-type", G_TYPE_STRING, src_type,
+        "wpe-original-src-path", G_TYPE_STRING, src_path,
+        NULL
+    );
+
     g_free (our_message);
-    gst_element_post_message(GST_ELEMENT(src), message);
+    gst_element_post_message(GST_ELEMENT(src), gst_message_new_custom(GST_MESSAGE_ELEMENT,
+                                                                      GST_OBJECT(src), structure));
     g_error_free(error);
+    gst_message_unref (forwarded);
 }
 
 static void
 webkit_extension_bus_message_received (GstWpeSrc *src, GVariant *params)
 {
-    GstStructure *structure;
-    const gchar *message_type, *src_name, *src_type, *src_path, *struct_str;
+    GstStructure *original_structure, *structure;
+    const gchar *src_name, *src_type, *src_path, *struct_str;
+    GstMessageType message_type;
+    GstMessage *forwarded;
 
-    g_variant_get (params, "(sssss)",
+    g_variant_get (params, "(issss)",
        &message_type,
        &src_name,
        &src_type,
@@ -226,23 +237,29 @@ webkit_extension_bus_message_received (GstWpeSrc *src, GVariant *params)
        &struct_str
     );
 
-    structure = (struct_str[0] != '\0') ? gst_structure_new_from_string(struct_str) : NULL;
-    if (!structure)
+    original_structure = (struct_str[0] != '\0') ? gst_structure_new_from_string(struct_str) : NULL;
+    if (!original_structure)
     {
         if (struct_str[0] != '\0')
             GST_ERROR_OBJECT(src, "Could not deserialize: %s", struct_str);
-        structure = gst_structure_new_empty("wpesrc");
+        original_structure = gst_structure_new_empty("wpesrc");
+
     }
 
-    gst_structure_set(structure,
-                      "wpesrc_original_message_type", G_TYPE_STRING, message_type,
-                      "wpesrc_original_src_name", G_TYPE_STRING, src_name,
-                      "wpesrc_original_src_type", G_TYPE_STRING, src_type,
-                      "wpesrc_original_src_path", G_TYPE_STRING, src_path,
-                      NULL);
+    forwarded = gst_message_new_custom(message_type,
+        GST_OBJECT (src), original_structure);
+    structure = gst_structure_new ("WpeForwarded",
+        "message", GST_TYPE_MESSAGE, forwarded,
+        "wpe-original-src-name", G_TYPE_STRING, src_name,
+        "wpe-original-src-type", G_TYPE_STRING, src_type,
+        "wpe-original-src-path", G_TYPE_STRING, src_path,
+        NULL
+    );
 
     gst_element_post_message(GST_ELEMENT(src), gst_message_new_custom(GST_MESSAGE_ELEMENT,
                                                                       GST_OBJECT(src), structure));
+
+    gst_message_unref (forwarded);
 }
 
 static gboolean
index 1d8afea..dd49ff7 100644 (file)
  * The wpesrc element is used to produce a video texture representing a web page
  * rendered off-screen by WPE.
  *
- * Starting from WPEBackend-FDO 1.6.x, software rendering support is available. This
- * features allows wpesrc to be used on machines without GPU, and/or for testing
- * purpose. To enable it, set the `LIBGL_ALWAYS_SOFTWARE=true` environment
- * variable and make sure `video/x-raw, format=BGRA` caps are negotiated by the
- * wpesrc element.
+ * Starting from WPEBackend-FDO 1.6.x, software rendering support is available.
+ * This features allows wpesrc to be used on machines without GPU, and/or for
+ * testing purpose. To enable it, set the `LIBGL_ALWAYS_SOFTWARE=true`
+ * environment variable and make sure `video/x-raw, format=BGRA` caps are
+ * negotiated by the wpesrc element.
  *
  * ## Example launch lines
  *
  * source pads.
  *
  * This source also relays GStreamer bus messages from the GStreamer pipelines
- * running inside the web pages. Error, warning and info messages are made ours
- * with the addition of the following fields into the GstMessage details (See
- * gst_message_parse_error_details(), gst_message_parse_warning_details() and
- * gst_message_parse_info_details()):
+ * running inside the web pages  as [element custom](gst_message_new_custom)
+ * messages which structure is called `WpeForwarded` and has the following
+ * fields:
  *
- * * `wpesrc_original_src_path`: [Path](gst_object_get_path_string) of the
- *   original element posting the message
- *
- * Other message types are posted as [element custom](gst_message_new_custom)
- * messages reusing the same GstStructure as the one from the message from the
- * message posted in the web page with the addition of the following fields:
- *
- * * `wpesrc_original_message_type`: Type of the original message from
- *    gst_message_type_get_name().
- * * `wpesrc_original_src_name`: Name of the original element posting the
+ * * `message`: The original #GstMessage
+ * * `wpesrc-original-src-name`: Name of the original element posting the
  *   message
- * * `wpesrc_original_src_type`: Name of the GType of the original element
+ * * `wpesrc-original-src-type`: Name of the GType of the original element
  *   posting the message
- * * `wpesrc_original_src_path`: [Path](gst_object_get_path_string) of the
+ * * `wpesrc-original-src-path`: [Path](gst_object_get_path_string) of the
  *   original element positing the message
  *
  * Note: This feature will be disabled if you disable the tracer subsystem.
index b6b8b6e..42a204d 100644 (file)
@@ -64,8 +64,10 @@ create_gerror_bus_msg (GstElement * element, GstMessage * message)
 
   msg = webkit_user_message_new ("gstwpe.bus_gerror_message",
       /* (message_type, src_path, error_domain, error_code, msg, debug_str, details_structure) */
-      g_variant_new ("(sssusss)",
-          gst_message_type_get_name (GST_MESSAGE_TYPE (message)),
+      g_variant_new ("(issssusss)",
+          GST_MESSAGE_TYPE (message),
+          GST_MESSAGE_SRC_NAME (message),
+          G_OBJECT_TYPE_NAME (GST_MESSAGE_SRC (message)),
           src_path,
           g_quark_to_string (error->domain),
           error->code, error->message, debug_str, details_structure)
@@ -144,8 +146,8 @@ gst_message_post_cb (GObject * object, GstClockTime ts, GstElement * element,
   } else {
     gchar *src_path = gst_object_get_path_string (GST_MESSAGE_SRC (message));
     msg = webkit_user_message_new ("gstwpe.bus_message",
-        g_variant_new ("(sssss)",
-            gst_message_type_get_name (GST_MESSAGE_TYPE (message)),
+        g_variant_new ("(issss)",
+            GST_MESSAGE_TYPE (message),
             GST_MESSAGE_SRC_NAME (message),
             G_OBJECT_TYPE_NAME (GST_MESSAGE_SRC (message)), src_path, str));
     g_free (src_path);