qroverlay: Add a GstQROverlay meta
authorThibault Saunier <tsaunier@igalia.com>
Fri, 4 Mar 2022 22:00:18 +0000 (22:00 +0000)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 27 Apr 2022 15:09:47 +0000 (15:09 +0000)
See documentation

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2299>

subprojects/gst-plugins-bad/ext/qroverlay/gstqroverlay.c

index beaacb7..cdde8cf 100644 (file)
  * ``` bash
  * gst-launch -v -m videotestsrc ! qroverlay ! fakesink silent=TRUE
  * ```
+ * Since 1.22 the `qroverlay` element also supports a #GstCustomMeta called
+ * `GstQROverlayMeta` which allows upstream elements to set the data to be
+ * rendered on the buffers that flow through it. This custom meta
+ * #GstStructure has the following fields:
+ *
+ * * #gchar* `data` (**mandatory**): The data to use to render the qrcode.
+ * * #gboolean `keep_data` (**mandatory**): Set to %TRUE if the data from that
+ *   metadata should be used as #qroverlay:data
+ *
  *
  * Since: 1.20
  */
@@ -76,6 +85,34 @@ get_qrcode_content (GstBaseQROverlay * base, GstBuffer * buf,
   gchar *content;
   GstQROverlay *self = GST_QR_OVERLAY (base);
 
+  GstCustomMeta *meta = gst_buffer_get_custom_meta (buf, "GstQROverlayMeta");
+  if (meta) {
+    gchar *data;
+    GstStructure *structure =
+        gst_custom_meta_get_structure ((GstCustomMeta *) meta);
+
+    if (gst_structure_get (structure, "data", G_TYPE_STRING, &data, NULL)) {
+      gboolean keep_data;
+
+      GST_OBJECT_LOCK (self);
+      self->data_changed = TRUE;
+      if (gst_structure_get_boolean (structure, "keep_data", &keep_data)
+          && keep_data) {
+        g_free (self->data);
+        self->data = g_strdup (self->data);
+      }
+      GST_OBJECT_UNLOCK (self);
+
+      *reuse_prev = FALSE;
+
+      return data;
+    }
+
+    GST_WARNING_OBJECT (self,
+        "Got a GstQROverlayMeta without a 'data' field in its struct");
+  }
+
+
   GST_OBJECT_LOCK (self);
   content = g_strdup (self->data);
   *reuse_prev = self->data_changed;
@@ -124,10 +161,12 @@ gst_qr_overlay_class_init (GstQROverlayClass * klass)
 {
   GObjectClass *gobject_class;
   GstElementClass *gstelement_class;
+  static const gchar *tags[] = { NULL };
 
   gobject_class = (GObjectClass *) klass;
   gstelement_class = (GstElementClass *) klass;
 
+
   gobject_class->set_property = gst_qr_overlay_set_property;
   gobject_class->get_property = gst_qr_overlay_get_property;
 
@@ -137,6 +176,8 @@ gst_qr_overlay_class_init (GstQROverlayClass * klass)
       "Overlay Qrcodes over each buffer with data passed in",
       "Thibault Saunier <tsaunier@igalia.com>");
 
+  gst_meta_register_custom ("GstQROverlayMeta", tags, NULL, NULL, NULL);
+
   g_object_class_install_property (gobject_class,
       PROP_DATA, g_param_spec_string ("data",
           "Data",